package com.zx.huawei;

import java.util.Scanner;

public class TestN {
    public static void main(String[] args) {

        System.out.println("输入人数:");
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        number_off(n);
    }

    static void number_off(int n) {
        boolean[] arr = new boolean[n];
        for (int i = 0; i < arr.length; i++) {
            arr[i] = true;
        }  //下标true说明还在圈里
        int leftCount = n;
        int countNum = 0;
        int index = 0;
        System.out.println("出圈序列");
        while (leftCount > 1) {
            if (arr[index] == true) {
                countNum++;   //报数递加
                if (countNum == 3) {
                    countNum = 0;  //从0开始继续报数
                    arr[index] = false;  //从此退出圈子
                    System.out.println((index + 1) + "");  //数组下标是0，标号起始值是1
                    leftCount--; //剩余人数减1
                }
            }

            index++;  //每报一次数 ，下标加1
            if (index == n) {
                //循环数数，当下标大于n，说明已经数了一圈
                index = 0;  //将下标设为0重新开始
            }
        }
        for (int i = 0; i < n; i++) {
            if (arr[i] == true) {
                System.out.println("最后剩下的人数" + (i + 1) + "号");  //数组起始下标是0  标号起始值是1
            }
        }
    }
}
